package org.sky.generator;

import org.apache.logging.log4j.Logger;
import org.sky.generator.database.analize.IAnalizeDatabase;
import org.sky.generator.database.analize.impl.MysqlAnalizeDatabase;
import org.sky.generator.database.model.Column;
import org.sky.generator.database.model.Table;
import org.sky.generator.generator.impl.*;
import org.sky.util.LogUtils;

import java.util.List;

/**
 * @author weifx
 * @Title: Generator
 * @ProjectName springboot-platform
 * @Description: TODO{自定义代码生成器}
 * @date 2019/2/25 23:33
 * @Version 1.0
 */
public class GeneratorApplication {
    private static Logger logger = LogUtils.getLogger(GeneratorApplication.class);
    /**
     * 代码生成配置参数
     */
    private static GeneratorConfig generatorConfig = GeneratorConfig.getInstance();

    public static void main(String[] args) {
        final String[] tables=generatorConfig.getTables();
        for(String tableName:tables){
            IAnalizeDatabase analizeDatabase = new MysqlAnalizeDatabase();
            Table table = analizeDatabase.getTable(tableName);
            List<Column> columnList = analizeDatabase.getCloumns(tableName);

            //生成实体类
            EntityGenerator eg = new EntityGenerator();
            eg.generate(generatorConfig,table,columnList);
            //生成Mapper接口
            MapperGenerator mg = new MapperGenerator();
            mg.generate(generatorConfig,table,columnList);
            //生成Mybatis文件
            MybatisGenerator mbg = new MybatisGenerator();
            mbg.generate(generatorConfig,table,columnList);

            //生成Service
            ServiceGenerator sg = new ServiceGenerator();
            sg.generate(generatorConfig,table,columnList);
            //生成Controller
            ControllerGenerator cg = new ControllerGenerator();
            cg.generate(generatorConfig,table,columnList);
            //生成view
            ViewGenerator vg = new ViewGenerator();
            vg.generate(generatorConfig,table,columnList);

       }
    }
}
